package com.kt.uokos.yimo.controller;

import com.kt.uokos.yimo.anno.RequiresPermissionsDesc;
import com.kt.uokos.yimo.service.SystemConfigService;
import com.kt.uokos.yimo.util.JacksonUtil;
import com.kt.uokos.yimo.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @description: TODO
 * @className: SystemConfigController.java
 * @author: Kang Hao
 * @date: 2022/4/29 20:16
 **/
@RestController
@RequestMapping("/admin/config/")
public class SystemConfigController {

    @Resource
    private SystemConfigService systemConfigService;

    @GetMapping("mall")
    public Object listmall(){
        Map<String, String> listmall = systemConfigService.listmall();
        return ResponseUtil.ok(listmall);
    }

    @PostMapping("mall")
    public Object updateMall(@RequestBody String body){
        Map<String, String> map = JacksonUtil.toMap(body);
        systemConfigService.updateMall(map);
        return ResponseUtil.ok();
    }

    @RequiresPermissions("admin:config:express:list")
    @RequiresPermissionsDesc(menu = {"配置管理", "运费配置"}, button = "详情")
    @GetMapping("express")
    public Object listExpress(){
        Map<String, String> listExpress = systemConfigService.listExpress();
            return ResponseUtil.ok(listExpress);
    }

    @PostMapping("express")
    public Object updateExpress(@RequestBody String body){
        Map<String, String> map = JacksonUtil.toMap(body);
        systemConfigService.updateExpress(map);
        return ResponseUtil.ok();
    }

    @GetMapping("/order")
    public Object listOrder(){
        Map<String, String> listOrder = systemConfigService.listOrder();
        return ResponseUtil.ok(listOrder);
    }

    @PostMapping("/order")
    public Object updateOrder(@RequestBody String body){
        Map<String, String> map = JacksonUtil.toMap(body);
        systemConfigService.updateOrder(map);
        return ResponseUtil.ok();
    }

    @GetMapping("/wx")
    public Object listWx(){
        Map<String, String> listWx = systemConfigService.listWx();
        return ResponseUtil.ok(listWx);
    }

    @PostMapping("/wx")
    public Object updateWx(@RequestBody String body){
        Map<String, String> map = JacksonUtil.toMap(body);
        systemConfigService.updateWx(map);
        return ResponseUtil.ok();
    }
}
